<template>
  <div style="height: 100%; width: 100%; position: relative;" ref="maindev">
    <div class="pagetop">
      <table style="width: 100%; font-size: 12px;white-space: nowrap;" border="0">
        <col style="width: 7%;" />
        <col style="width: 11%;" />
        <col style="width: 1%;" />
        <col style="width: 11%;" />
        <col style="width: 7%;" />
        <col style="width: 12%;" />
        <col style="width: 7%;" />
        <col style="width: 10%;" />
        <col style="width: 7%;" />
        <col style="width: 10%;" />
        <col style="width: 7%;" />
        <col style="width: 10%;" />
        <tr>
          <td align="right">
            <el-dropdown @command="handleCommand" style="font-size: 12px;">
              <u class="el-dropdown-link">
                {{ datename }}
              </u>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="标本日期">
                  <font font-size="12px">标本日期</font>
                </el-dropdown-item>
                <el-dropdown-item command="报告日期">
                  <font font-size="12px">报告日期</font>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </td>
          <td>
            <el-date-picker v-model="searchobj.strdate" :clearable="false" type="date" placeholder="选择日期"
              value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
          </td>
          <td>至</td>
          <td>
            <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false" placeholder="选择日期"
              value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
          </td>
          <td align="right">标本类型</td>
          <td>
            <el-select v-model="searchobj.sample"
              @dblclick.native="popMultipleChk(searchobj.sample, 'sample', specimenOption, '请选择标本类型')" filterable
              clearable style="width: 100%;">
              <el-option v-for="(item, index) in specimenOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
          <td align="right">病人类型</td>
          <td>
            <!-- @dblclick.native="popMultipleChk(txtpattype, 'txtpattype', pattypeOption, '病人类型选择')" -->
            <el-select v-model="searchobj.pattype" filterable clearable style="width: 100%;">
              <el-option v-for="(item, index) in pattypeOption" :value="item.data" :label="item.display"
                :key="index"></el-option>
            </el-select>
          </td>
          <td align="right">病人性别</td>
          <td>
            <el-select v-model="searchobj.patsex" style="width: 100%;" clearable>
              <el-option v-for="(item, index) in sexOption" :key="index" :label="item.label"
                :value="item.value"></el-option>
            </el-select>
          </td>
          <td align="right">科室组</td>
          <td>
            <el-select v-model="searchobj.deptgroup"
              @dblclick.native="popMultipleChk(searchobj.deptgroup, 'deptgroup', deptgroupOption, '请选择科室组')" filterable
              clearable>
              <el-option v-for="(item, index) in deptgroupOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td align="right">报告单元</td>
          <td colspan="3">
            <el-select v-model="searchobj.rptunitid"
              @dblclick.native="popMultipleChk(searchobj.rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')" filterable
              clearable style="width:100%">
              <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
          <td align="right">送检医院</td>
          <td>
            <el-select v-model="searchobj.hospitalcode"
              @dblclick.native="popMultipleChk(searchobj.hospitalcode, 'hospitalcode', hospOption, '请选择送检医院')" filterable
              clearable style="width: 100%;">
              <el-option v-for="(item, index) in hospOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
          <td align="right">申请科室</td>
          <td>
            <el-select v-model="searchobj.reqdept"
              @dblclick.native="popMultipleChk(searchobj.reqdept, 'reqdept', deptOption, '申请科室选择')" filterable clearable
              style="width: 100%;">
              <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display">
              </el-option>
            </el-select>
          </td>
          <td align="right">申请病区</td>
          <td>
            <el-select v-model="searchobj.reqward"
              @dblclick.native="popMultipleChk(searchobj.reqward, 'reqward', wardOption, '病区选择')" filterable clearable>
              <el-option v-for="(item, index) in wardOption" :key="index" :value="item.data" :label="item.display">
              </el-option>
            </el-select>
          </td>
          <td align="right">细菌组</td>
          <td>
            <el-select v-model="searchobj.germcomb"
              @dblclick.native="popMultipleChk(searchobj.germcomb, 'germcomb', germcombOption, '细菌组')" filterable
              clearable>
              <el-option v-for="(item, index) in germcombOption" :key="index" :value="item.data" :label="item.display">
              </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td align="right">病人诊断</td>
          <td colspan="3">
            <el-input v-model="searchobj.pat_diag" clearable style="width: 100%;"></el-input>
          </td>
          <td align="right">诊断ICD</td>
          <td>
            <el-input v-model="searchobj.pat_diag_icd" clearable></el-input>
          </td>
          <td align="right">统计方式</td>
          <td>
            <el-radio-group v-model="searchobj.bypat" @change="bypatChange">
              <el-radio :label="0">按标本</el-radio>
              <el-radio :label="1">按病人</el-radio>
              <el-radio :label="2">按报告</el-radio>
            </el-radio-group>
          </td>
          <!-- <td align="right">细菌标志</td>
                    <td>
                        <el-select v-model="searchobj.germflag" placeholder="请选择" style="width:100%" filterable clearable>
                            <el-option key="0" label="普通项目" value="0"></el-option>
                            <el-option key="1" label="培养阴性结果" value="1"></el-option>
                            <el-option key="2" label="致病菌" value="2"></el-option>
                            <el-option key="3" label="正常菌种" value="3"></el-option>
                            <el-option key="4" label="涂片结果" value="4"></el-option>
                        </el-select>
                    </td> -->
          <td colspan="2" style="text-align:center">
            <el-checkbox v-model="searchobj.germflag2" true-label="1" false-label="0">
              仅显示致病菌
            </el-checkbox>
          </td>
          <td colspan="2" style="text-align:center">
            <el-checkbox v-model="searchobj.rechkreport" true-label="1" false-label="0">
              仅已审核的报告
            </el-checkbox>
          </td>
        </tr>
        <tr>
          <td align="right"><span @click="Btncountitem"
              style="cursor: pointer;font-weight:bold;font-size:14px">统计项目</span></td>
          <td colspan="3">
            <div v-if="infocode == ''" @click="Btncountitem">
              <span style="color:red;cursor:pointer;font-size:15px">点击该位置选择统计项目</span>
            </div>
            <div v-else>
              <div @click="Btncountitem" style="width: 100%;cursor: pointer;color:#409EFF">
                <u>{{ infoitem }}</u>
              </div>
              <el-input v-model="infocode" readonly v-show="false"></el-input>
            </div>
          </td>
          <td align="right">关注的耐药机制</td>
          <td>
            <el-select v-model="searchobj.showresistrules"
              @dblclick.native="popMultipleChk(searchobj.showresistrules, 'showresistrules', rescodeOption, '耐药机制选择')"
              filterable clearable style="width:100%">
              <el-option v-for="(item, index) in rescodeOption" :value="item.data" :label="item.display"
                :key="index"></el-option>
            </el-select>
          </td>
          <td align="right">细菌</td>
          <td>
            <!-- <rm-ddl-common datatype="deptcomb" dataname="科室组" v-model="searchobj.deptgroup" width="100%" @change="deptgroupChange"></rm-ddl-common> -->
            <el-select v-model="searchobj.germrptitemcode"
              @dblclick.native="popMultipleChk(searchobj.germrptitemcode, 'germrptitemcode', germOption, '请选择细菌')"
              filterable clearable style="width:100%">
              <el-option v-for="(item, index) in germOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td colspan="13" align="right">
            <el-button @click.native="BtnQuery" v-has="'PINQUERY'" type="primary" icon="el-icon-search">查询</el-button>
            <!-- <el-button @click.native="BtnSort" icon="el-icon-sort">排序</el-button> -->
            <el-button @click.native="BtnClear" icon="el-icon-close">清除</el-button>
            <el-button @click.native="BtnExport" icon="el-icon-upload2">导出</el-button>
            <!-- <el-button @click.native="BtnPrint" icon="el-icon-printer">打印</el-button> -->
          </td>
        </tr>
      </table>
    </div>
    <div class="pagecenter">
      <div class="middle-center">
        <vxe-table :data.sync="tableData" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border
          height="auto" highlight-current-row class="mytable-style" highlight-hover-column highlight-hover-row
          how-header-overflow ref="xTable" resizable show-overflow size="mini" stripe show-header-overflow
          :optimization="{ animat: false }" header-align="center" :key="xTablekey" show-footer
          :footer-method="footerMethod" :footer-cell-class-name="footerCellClassName" :cell-class-name="cellClassName"
          :loading="loading" :edit-config="{ trigger: 'dblclick', mode: 'cell' }" @cell-dblclick="DblEvent">
          <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable
            v-for="items in tableColumn" :formatter="formatFun" :align="items.position"></vxe-table-column>
          <vxe-table-column field="samplecnt" sortable :title="fieldtitle" width="80" align="center"></vxe-table-column>
          <vxe-table-column field="cnt4" sortable title="涂片结果" width="80" align="center"></vxe-table-column>
          <vxe-table-column field="cnt1" sortable title="阴性数" width="70" align="center"></vxe-table-column>
          <vxe-table-column field="pcnt" sortable title="阳性数" width="70" align="center"></vxe-table-column>
          <vxe-table-column field="prate" sortable title="阳性率" width="70" align="center"></vxe-table-column>
          <vxe-table-column field="prates" sortable title="阳性率(总)" width="90" align="center"></vxe-table-column>
          <vxe-table-column field="sampprates" sortable title="标本占有率(总)" width="120" align="center"></vxe-table-column>
          <vxe-table-column field="pcntprates" sortable title="阳性占有率(总)" width="120" align="center"></vxe-table-column>
          <template>
            <vxe-table-column v-for="resist in resistrulescolList" :key="resist.Item2" :field="resist.Item2" sortable
              :title="resist.Item1" width="120" align="center"></vxe-table-column>
          </template>
        </vxe-table>
      </div>
    </div>
    <!--统计项目-->
    <el-dialog title="统计项目" :visible.sync="dialogcountItem" width="800px" v-el-drag-dialog :append-to-body="true"
      :close-on-click-modal="false">
      <div style="width: 100%; height: 300px; margin-top: 5px;">
        <div style="width: 70%; height: 100%; float: left; overflow: auto; border: 1px solid #ccc;">
          <div id="left_nav" class="left_nav">

            <div @click="showseq = 1" :class="showseq == 1 ? 'active' : ''" ref="left1">
              1 检验信息
            </div>
            <div @click="showseq = 2" :class="showseq == 2 ? 'active' : ''" ref="left2">
              2 病人信息
            </div>
            <div @click="showseq = 3" :class="showseq == 3 ? 'active' : ''" ref="left3">
              5 检验日期
            </div>
          </div>
          <div id="right_nav" class="right_nav">
            <table class="table1style" style="width: 100%; padding: 10px;">
              <tr v-show="showseq == 1">
                <td>
                  <el-checkbox @change="chkcountitem($event, '耐药机制', 'rp_result4')"
                    v-model="rp_result4">耐药机制</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '报告单元', 'rp_rptunitname')"
                    v-model="rp_rptunitname">报告单元</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '样本类型', 'rp_specimen_code')"
                    v-model="rp_specimen_code">样本类型</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '项目', 'rp_rpt_itemname')"
                    v-model="rp_rpt_itemname">项目</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '送检医院', 'rp_hospitalcode')"
                    v-model="rp_hospitalcode">送检医院</el-checkbox>
                </td>
              </tr>
              <tr v-show="showseq == 2">
                <td>
                  <el-checkbox @change="chkcountitem($event, '病人类型', 'rp_pat_typecode')"
                    v-model="rp_pat_typecode">病人类型</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '性别', 'rp_pat_sex')" v-model="rp_pat_sex">性别</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '病区', 'rp_req_wardno')"
                    v-model="rp_req_wardno">病区</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '科室', 'rp_req_deptno')"
                    v-model="rp_req_deptno">科室</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '诊断', 'rp_pat_diag')" v-model="rp_pat_diag">诊断</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '诊断ICD', 'rp_pat_diag_icd')"
                    v-model="rp_pat_diag_icd">诊断ICD</el-checkbox>
                </td>
              </tr>
              <tr v-show="showseq == 3">
                <td>
                  <el-checkbox @change="chkcountitem($event, '年', 'rp_sampleyear')"
                    v-model="rp_sampleyear">年</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '月', 'rp_samplemonth')"
                    v-model="rp_samplemonth">月</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '日', 'rp_sampleday')" v-model="rp_sampleday">日</el-checkbox>
                </td>
              </tr>
            </table>
          </div>
        </div>
        <div style="width: 29%; height: 100%; float: left; margin-left: 5px; overflow: auto;">
          <vxe-table show-overflow ref="xTable1" height="auto" :select-config="{ reserve: true }"
            :sort-config="{ trigger: 'cell' }" :mouse-config="{ selected: true }" :data.sync="tableData1" border
            size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe
            @current-change="currentChangeEvent1" @cell-dblclick="xTable1dblclick">
            <vxe-table-column type="index" title="NO." width="50" align="center"></vxe-table-column>
            <vxe-table-column field="countitem" title="统计项目(双击删除)" width="160" sortable
              header-align="center"></vxe-table-column>
          </vxe-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button icon="el-icon-top" @click="tabledatafirst()">首位</el-button>
        <el-button icon="el-icon-top-right" @click="tabledataup()">上移</el-button>
        <el-button icon="el-icon-bottom-right" @click="tabledatadown()">下移</el-button>
        <el-button icon="el-icon-bottom" @click="tabledatalast()">末位</el-button>
        <el-button @click="tableClear">清 除</el-button>
        <el-button type="primary" @click="dialogcountItemsave">确 定</el-button>
        <el-button @click="dialogcountItem = false">取 消</el-button>
      </span>
    </el-dialog>
    <!--报告项目--->
    <el-dialog width="1000px" top="10px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false"
      title="报告项目" :visible.sync="dialogTableVisible1" :destroy-on-close="true">
      <rm-pop-selrptitem @cancel="dialogTableVisible1 = false" @selitem="addrptitem"></rm-pop-selrptitem>
    </el-dialog>

    <!--多选弹窗--->
    <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle"
      :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
      <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname"
        @change="closedialog"></rm-SqlMultiple>
    </el-dialog>
    <!--samplecnt弹窗-->
    <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="dialogpoptitle"
      :visible.sync="dialogsamplepop" width="1000px">
      <div style="height: 500px">
        <vxe-table :data.sync="popsampleTableData" :select-config="{ reserve: true }" :loading="sampleloading"
          :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row class="mytable-style"
          highlight-hover-column highlight-hover-row how-header-overflow ref="poplXTable" resizable show-overflow
          size="mini" stripe show-header-overflow header-align="center" show-footer>
          <vxe-table-column field="barcode_reportid" sortable title="条码号/报告ID" width="110"
            show-overflow></vxe-table-column>
          <vxe-table-column field="sampleno" sortable title="标本号" width="110" show-overflow></vxe-table-column>
          <vxe-table-column field="sampledate" sortable title="标本日期" width="70"
            :formatter="['toDateString', 'yyyy-MM-dd']" show-overflow></vxe-table-column>
          <vxe-table-column field="rpt_itemcode" sortable title="报告项目代码" width="110" show-overflow></vxe-table-column>
          <vxe-table-column field="rpt_itemname" sortable title="报告项目名称" width="110" show-overflow></vxe-table-column>
          <vxe-table-column field="pat_name" sortable title="姓名" width="70" show-overflow></vxe-table-column>
          <vxe-table-column field="pat_sexname" sortable title="性别" width="40" show-overflow></vxe-table-column>
          <vxe-table-column field="pat_agestr" sortable title="年龄岁数" width="70" show-overflow></vxe-table-column>
          <vxe-table-column field="deptname" sortable title="科室" width="130" show-overflow></vxe-table-column>
          <vxe-table-column field="wardname" sortable title="病区" width="130" show-overflow></vxe-table-column>
          <vxe-table-column field="pat_typecodename" sortable title="病人类别" width="70" show-overflow></vxe-table-column>
        </vxe-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogsamplepop = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS911",
  data() {
    return {
      sexOption: [
        { label: "", value: "" },
        { label: "男", value: "1" },
        { label: "女", value: "2" },
        { label: "未知", value: "3" },
      ],
      chargeflagOption: [
        { label: "未收费", value: "0" },
        { label: "已收费", value: "1" },
        { label: "等待退费", value: "8" },
        { label: "已退费", value: "9" },
        { label: "免费", value: "5" },
      ],
      defaultColumn: [
        { title: "耐药机制", field: "rp_result4", width: "100" },
        { title: "报告单元", field: "rp_rptunitname", width: "180" },
        { title: "样本类型", field: "rp_specimen_code", width: "100" },
        { title: "项目", field: "rp_rpt_itemname", width: "200" },
        { title: "送检医院", field: "rp_hospitalcode", width: "200" },
        { title: "病人类型", field: "rp_pat_typecode", width: "80", position: "center" },
        { title: "性别", field: "rp_pat_sex", width: "50", position: "center" },
        { title: "病区", field: "rp_req_wardno", width: "100" },
        { title: "科室", field: "rp_req_deptno", width: "100" },
        { title: "诊断", field: "rp_pat_diag", width: "100" },
        { title: "诊断ICD", field: "rp_pat_diag_icd", width: "100" },
        { title: "年", field: "rp_sampleyear", width: "60", position: "center" },
        { title: "月", field: "rp_samplemonth", width: "80", position: "center" },
        { title: "日", field: "rp_sampleday", width: "100", position: "center" },
      ],
      loading: false,
      is_showselother: false,
      dialogcountItem: false,
      dialogTableVisible1: false,
      dialogMultipleVisible: false,
      option1: [],
      option2: [],
      fieldtitle: "标本数",
      fieldname: "",
      tableColumn: [],
      ExporttableColumn: [],
      tableData: [],
      tableData1: [],
      showseq: 1,
      currRowIndex: 0,
      xTablekey: 0,
      datename: "标本日期",
      multichktitle: "",
      datecode: "1",
      txtstasticsmod: "", //弹窗统计模版
      stasticsmodOption: [], //统计模版列表
      txtquerymod: "", //查询模版
      querymodOption: [], //查询模版列表
      pattypeOption: [],
      deptOption: [],
      wardOption: [],
      hospOption: [],
      doctorOption: [],
      rptunitOption: [],
      rptunitGroupOption: [],
      reportcommOption: [],
      labgroupOption: [],
      specimenOption: [],
      deptgroupOption: [], //deptcomb
      germcombOption: [],
      rescodeOption: [],
      //以下为查询条件
      searchobj: {
        strdate: this.$pub.InitDateTime2(0).datefrom,
        enddate: this.$pub.InitDateTime2(0).dateto,
        sample: "",
        pattype: "",
        patsex: "",
        deptgroup: "",
        rptunitid: "",
        hospitalcode: "",
        reqdept: "",
        reqward: "",
        germcomb: "",
        pat_diag: "",
        pat_diag_icd: "",
        rechkreport: "",
        germflag2: "",
        bypat: 0,
        showresistrules: "",
        germrptitemcode: "",
      },
      infoitem: "", //标本类型,项目
      infocode: "", //rp_specimen_code,rp_rpt_itemname
      //以下为统计项目
      rp_result4: false,
      rp_rptunitname: false,
      rp_specimen_code: false,
      rp_rpt_itemname: false,
      rp_hospitalcode: false,
      rp_pat_typecode: false,
      rp_pat_sex: false,
      rp_req_wardno: false,
      rp_req_deptno: false,
      rp_pat_diag: false,
      rp_pat_diag_icd: false,
      rp_sampleyear: false,
      rp_samplemonth: false,
      rp_sampleday: false,
      //以下为排序数组
      sortArr: [],
      SortTableColumn: [
        { title: "标本数", field: "cp_samplecnt" },
        { title: "涂片结果", field: "cp_cnt" },
        { title: "阴性数", field: "cp_amt" },
        { title: "阳性数", field: "cp_rs" },
        { title: "阳性率", field: "cp_redocnt" },
        { title: "阳性率(总)", field: "cp_amt" },
        { title: "标本占有率(总)", field: "cp_rs" },
        { title: "阳性占有率(总)", field: "cp_redocnt" },
      ],
      dialogsamplepop: false,
      dialogpoptitle: "",
      popsampleTableData: [],
      sampleloading: false,
      infocodedic: [],
      resdictList: [],
      resistrulescolList: [],
      exportTableColLen: 0,
      germOption: [],
    };
  },
  created() {
    this.initOption();
    //this.InitPage(); //初始化主列表
  },
  mounted() { },
  updated() { },
  methods: {
    popMultipleChk(e, fieldname, option, title) {
      let temp = XEUtils.clone(option, true);
      this.option1 = [];
      this.option2 = [];
      if (e != "") {
        let k = e.split(",");
        k.forEach((item) => {
          let ndata = temp.find((m) => m.data == item);
          if (ndata != undefined && ndata != null) {
            this.option2.push(ndata);
          }
        });
        temp.forEach((item) => {
          if (k.indexOf(item.data + "") < 0) {
            this.option1.push(item);
          }
        });
      } else {
        this.option1 = temp;
      }
      this.fieldname = fieldname;
      this.multichktitle = title;
      this.dialogMultipleVisible = true;
    },
    closedialog(value, name) {
      console.log(name)
      if (value != "close") {
        this.searchobj[name] = value;
      }
      this.dialogMultipleVisible = false;
    },
    addrptitem(rptitemcodeinfos) {
      this.txtrptitem = "";
      for (var i = 0; i < rptitemcodeinfos.length; i++) {
        if (this.txtrptitem == "") {
          this.txtrptitem = rptitemcodeinfos[i].rpt_itemcode;
        } else {
          this.txtrptitem += "," + rptitemcodeinfos[i].rpt_itemcode;
        }
      }
      this.dialogTableVisible1 = false;
    },
    tableClear() {
      this.rp_result4 = false;
      this.rp_rptunitname = false;
      this.rp_specimen_code = false;
      this.rp_rpt_itemname = false;
      this.rp_hospitalcode = false;
      this.rp_pat_typecode = false;
      this.rp_pat_sex = false;
      this.rp_req_wardno = false;
      this.rp_req_deptno = false;
      this.rp_pat_diag = false;
      this.rp_pat_diag_icd = false;
      this.rp_sampleyear = false;
      this.rp_samplemonth = false;
      this.rp_sampleday = false;
      this.tableData1 = [];
    },
    DblEvent({ row, rowIndex, $rowIndex, column }) {
      var bycolumn = column.property;
      let field = this.infocode.split(",");
      if (column.property == "samplecnt") {
        this.dialogpoptitle = this.fieldtitle + "详情";
      } else if (column.property == "cnt4") {
        this.dialogpoptitle = "涂片结果详情";
      } else if (column.property == "cnt1") {
        this.dialogpoptitle = "阴性详情";
      } else if (column.property == "pcnt") {
        this.dialogpoptitle = "阳性详情";
      }
      if (column.property == "samplecnt" || column.property == "cnt4" || column.property == "cnt1" || column.property == "pcnt") {
        this.$tool
          .request({
            url: "LIS/LIS9/LIS911",
            method: "post",
            timeout: 600000,
            data: {
              action: "getDetail",
              infocode: this.infocode, //要查询的列数
              sortArr: this.sortArr, //排序
              datecode: this.datecode,
              infocodeval: row,
              bycolumn: bycolumn,
              ...this.searchobj,
            },
          })
          .then((response) => {
            this.popsampleTableData = XEUtils.clone(response.data, true);
            this.dialogsamplepop = true;
          })
          .catch((e) => {
            this.$message.warning(e);
          });
      }
    },
    //弹出统计项目
    Btncountitem() {
      //重置所有选项
      this.rp_result4 = false;
      this.rp_rptunitname = false;
      this.rp_specimen_code = false;
      this.rp_rpt_itemname = false;
      this.rp_hospitalcode = false;
      this.rp_pat_typecode = false;
      this.rp_pat_sex = false;
      this.rp_req_wardno = false;
      this.rp_req_deptno = false;
      this.rp_pat_diag = false;
      this.rp_pat_diag_icd = false;
      this.rp_sampleyear = false;
      this.rp_samplemonth = false;
      this.rp_sampleday = false;

      this.dialogcountItem = true; //开窗
      //表格及checkbox重新赋值
      setTimeout(() => {
        this.$refs.xTable1.tableData = [];
        if (this.infoitem != "") {
          let name = this.infoitem.split(",");
          let code = this.infocode.split(",");
          let datas = this.$refs.xTable1.tableData;
          for (let i = 0; i < name.length; i++) {
            let finddatas = datas.filter((item) => item.countitem == name[i]);
            if (finddatas.length == 0) {
              this.$refs.xTable1.insert({ countitem: name[i], countcode: code[i] }).then(({ row }) => {
                this.$refs.xTable1.setCurrentRow(row);
              });
              this.currRowIndex = name.length - 1;
            }
            this[code[i]] = true;
          }
        }
      }, 20);
    },
    //选择统计项目
    chkcountitem(e, name, code) {
      let tablelist = this.$refs.xTable1.tableData;
      let ishave = tablelist.find((m) => m.countitem == name);
      if (e) {
        if (tablelist.length <= 9) {
          if (ishave == undefined) {
            //防止重复插入
            this[code] = true;
            this.$refs.xTable1.insert({ countitem: name, countcode: code }).then(({ row }) => {
              this.$refs.xTable1.setCurrentRow(row);
              this.currRowIndex = tablelist.length - 1;
            });
          }
        } else {
          this[code] = false;
          this.$alert("最多只能添加10条统计项目！", "提示", {
            confirmButtonText: "确定",
          });
        }
      } else {
        try {
          if (ishave != undefined) {
            this[code] = false;
            var alld = this.$refs.xTable1.tableData;
            var rowindex = alld.indexOf(ishave);
            this.$refs.xTable1.remove(ishave);
            let havedata = this.$refs.xTable1.tableData;
            if (havedata.length > 0) {
              if (rowindex >= havedata.length) rowindex = havedata.length - 1;
              let selectrow = havedata[rowindex];
              this.$refs.xTable1.setCurrentRow(selectrow);
              this.currRowIndex = rowindex;
            }
          }
        } catch (e) {
          console.log("error", e);
        }
      }
    },
    //展开查询列表
    btn_showselother() {
      this.is_showselother = !this.is_showselother;
      let mainheight = this.$refs.maindev.offsetHeight;
      if (this.is_showselother) {
        this.icon_showselother = "el-icon-caret-top";
        this.pagetopstyle.height = "170px";
        this.pagecenter.top = "174px";
        this.reportheight = mainheight - 315;
        if (this.is_ym) {
          this.ymresultheight = mainheight - 485;
        } else {
          this.resultheight = mainheight - 280;
        }
      } else {
        this.icon_showselother = "el-icon-caret-bottom";
        this.pagetopstyle.height = "105px";
        this.pagecenter.top = "109px";
        this.reportheight = mainheight - 159;
        if (this.is_ym) {
          this.ymresultheight = mainheight - 326;
        } else {
          this.resultheight = mainheight - 114;
        }
      }
    },
    dialogcountItemsave() {
      let data = this.$refs.xTable1.tableData;
      let res1 = "";
      let res2 = "";
      if (data.length > 0) {
        data.forEach((element) => {
          if (res2 == "") {
            res2 = element.countitem;
            res1 = element.countcode;
          } else {
            res2 += "," + element.countitem;
            res1 += "," + element.countcode;
          }
        });
      }
      this.infoitem = res2;
      this.infocode = res1;
      this.dialogcountItem = false;
    },
    currentChangeEvent1({ row, $rowIndex }) {
      this.currRowIndex = $rowIndex;
    },
    tabledataup() {
      if (this.currRowIndex > 0) {
        let upData = this.$refs.xTable1.tableData[this.currRowIndex - 1];
        let currentrow = this.$refs.xTable1.tableData[this.currRowIndex];
        this.$refs.xTable1.tableData.splice(this.currRowIndex - 1, 1);
        this.$refs.xTable1.tableData.splice(this.currRowIndex, 0, upData);
        this.currRowIndex = this.currRowIndex - 1;
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(currentrow);
        });
      }
    },
    tabledatadown() {
      if (this.currRowIndex !== this.$refs.xTable1.tableData.length - 1) {
        let downData = this.$refs.xTable1.tableData[this.currRowIndex + 1];
        let currentrow = this.$refs.xTable1.tableData[this.currRowIndex];
        this.$refs.xTable1.tableData.splice(this.currRowIndex + 1, 1);
        this.$refs.xTable1.tableData.splice(this.currRowIndex, 0, downData);
        this.currRowIndex = this.currRowIndex + 1;
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(currentrow);
        });
      }
    },
    tabledatalast() {
      if (this.currRowIndex != this.$refs.xTable1.tableData.length - 1) {
        let lastData = this.$refs.xTable1.tableData[this.currRowIndex];
        this.$refs.xTable1.tableData.splice(this.currRowIndex, 1);
        this.$refs.xTable1.tableData.splice(this.$refs.xTable1.tableData.length, 0, lastData);
        this.currRowIndex = this.$refs.xTable1.tableData.length - 1;
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(lastData);
        });
      }
    },
    tabledatafirst() {
      if (this.currRowIndex > 0) {
        let firstData = this.$refs.xTable1.tableData[this.currRowIndex];
        this.$refs.xTable1.tableData.splice(this.currRowIndex, 1);
        this.$refs.xTable1.tableData.splice(0, 0, firstData);
        this.currRowIndex = 0;
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(firstData);
        });
      }
    },
    handleCommand(name) {
      this.datename = name;
      if (name == "标本日期") {
        this.datecode = "1";
      } else {
        this.datecode = "2";
      }
    },
    async initOption() {
      try {
        const res = await this.$tool.request({
          url: "LIS/LIS6/LIS610",
          method: "post",
          data: {
            action: "initOption",
          },
        });

        this.pattypeOption = res.pattypeOption;
        this.deptOption = res.deptOption;
        this.hospOption = res.hospOption;
        this.doctorOption = res.doctorOption;
        this.rptunitOption = res.rptunitOption;
        this.rptunitGroupOption = res.rptunitGroupOption;
        this.reportcommOption = res.reportcommOption;
        this.wardOption = res.wardOption;
        this.labgroupOption = res.labgroupOption;
        this.specimenOption = res.specimenOption;
        this.userOption = res.userOption;
        this.germcombOption = res.germcombOption;
        this.deptgroupOption = res.deptgroupOption;
        this.rescodeOption = res.rescodeOption;
        this.germOption = res.germOption;
      } catch (e) {
        this.$message.warning(e);
      }
    },
    BtnQuery() {
      this.InitPage();
    },
    BtnSort() {
      this.$rmsort(
        { tableColumn: this.SortTableColumn, sortArr: this.sortArr },
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then((res) => {
          this.sortArr = res.data;
          this.InitPage();
        })
        .catch(() => { });
    },
    BtnClear() {
      this.searchobj = {
        strdate: this.$pub.InitDateTime2(0).datefrom,
        enddate: this.$pub.InitDateTime2(0).dateto,
        sample: "",
        pattype: "",
        patsex: "",
        deptgroup: "",
        rptunitid: "",
        hospitalcode: "",
        reqdept: "",
        reqward: "",
        germcomb: "",
        pat_diag: "",
        pat_diag_icd: "",
        rechkreport: "",
        germflag2: "",
        bypat: 0,
        showresistrules: "",
        germrptitemcode: "",
      };
      this.infoitem = ""; //标本类型,项目
      this.infocode = ""; //rp_specimen_code,rp_rpt_itemname
      this.tableData = [];
    },
    BtnExport() {
      // let options = {
      //     filename: "LIS911 细菌阳性率统计.csv",
      // };
      // this.$refs.xTable.exportCsv(options);
      // this.ExporttableColumn = [];
      // let tableColumn = this.$refs.xTable.getColumns();
      // tableColumn.forEach((item) => {
      //     this.ExporttableColumn.push({ title: item.title, field: item.property });
      // });
      // this.$pub.exportTableExcel(this.tableData, this.ExporttableColumn, "LIS911 细菌阳性率统计.xlsx");
      let data = this.getExportData();
      let filtertxt = this.getExportFilter();
      this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS911 细菌阳性率统计.xlsx", filtertxt, "统计条件：");
    },
    // 获取当前导出文件的所有查询条件
    getExportFilter() {
      let filtertxt = this.datename + ":" + XEUtils.toDateString(this.searchobj.strdate, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.searchobj.enddate, "yyyy-MM-dd") + "; ";
      if (this.searchobj.sample) filtertxt += "标本类型:" + this.getOptionName(this.specimenOption.filter((item) => ("," + this.searchobj.sample + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.pattype) filtertxt += "病人类型:" + this.getOptionName(this.pattypeOption.filter((item) => this.searchobj.pattype == item.data)) + "; ";
      if (this.searchobj.patsex) filtertxt += "病人性别:" + this.getOptionName(this.sexOption.filter((item) => this.searchobj.patsex == item.value)) + "; ";
      if (this.searchobj.deptgroup) filtertxt += "科室组:" + this.getOptionName(this.deptgroupOption.filter((item) => ("," + this.searchobj.deptgroup + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.rptunitid) filtertxt += "报告单元:" + this.getOptionName(this.rptunitOption.filter((item) => ("," + this.searchobj.rptunitid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.hospitalcode) filtertxt += "送检医院:" + this.getOptionName(this.hospOption.filter((item) => ("," + this.searchobj.hospitalcode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.reqdept) filtertxt += "申请科室:" + this.getOptionName(this.deptOption.filter((item) => ("," + this.searchobj.reqdept + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.reqward) filtertxt += "申请病区:" + this.getOptionName(this.wardOption.filter((item) => ("," + this.searchobj.reqward + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.germcomb) filtertxt += "细菌组:" + this.getOptionName(this.germcombOption.filter((item) => ("," + this.searchobj.germcomb + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.pat_diag) filtertxt += "病人诊断:" + this.searchobj.pat_diag + "; ";
      if (this.searchobj.pat_diag_icd) filtertxt += "诊断ICD:" + this.searchobj.pat_diag_icd + "; ";
      if (this.searchobj.bypat) filtertxt += "统计方式:" + (this.searchobj.bypat == 0 ? "按标本" : this.searchobj.bypat == 1 ? "按病人" : "按报告") + "; ";
      if (this.searchobj.germflag2 == "1") filtertxt += "仅显示致病菌; ";
      if (this.searchobj.rechkreport == "1") filtertxt += "仅已审核的报告; ";
      if (this.infocode) filtertxt += "统计项目:" + this.infoitem + "; ";
      if (this.searchobj.showresistrules) filtertxt += "关注的耐药机制:" + this.getOptionName(this.rescodeOption.filter((item) => ("," + this.searchobj.showresistrules + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.germrptitemcode) filtertxt += "细菌：" + this.getOptionName(this.germOption.filter((item) => ("," + this.searchobj.germrptitemcode + ",").indexOf("," + item.data + ",") > -1)) + "; "
      return filtertxt;
    },
    getOptionName(option) {
      if (option && option.length > 0) {
        let optionname = "";
        option.forEach((item) => {
          if (item.hasOwnProperty("display")) {
            optionname += item.display + ",";
          } else {
            optionname += item.label + ",";
          }
        });
        return optionname.substring(0, optionname.length - 1);
      } else {
        return "";
      }
    },
    getExportData(index) {
      let datas = this.$refs.xTable.afterFullData;
      let exportColumn = XEUtils.clone(this.tableColumn, true);
      exportColumn.push({ title: this.fieldtitle, field: "samplecnt" });
      exportColumn.push({ title: "涂片结果", field: "cnt4" });
      exportColumn.push({ title: "阴性数", field: "cnt1" });
      exportColumn.push({ title: "阳性数", field: "pcnt" });
      exportColumn.push({ title: "阳性率", field: "prate" });
      exportColumn.push({ title: "阳性率(总)", field: "prates" });
      exportColumn.push({ title: "标本占有率(总)", field: "sampprates" });
      exportColumn.push({ title: "阳性占有率(总)", field: "pcntprates" });
      if (this.resistrulescolList && this.resistrulescolList.length > 0) {
        this.resistrulescolList.forEach(element => {
          exportColumn.push({ title: element.Item1, field: element.Item2 });
        });
      }
      this.exportTableColLen = exportColumn.length;
      let columns = exportColumn.filter((item) => item.field);
      let footerData = {};
      columns.forEach((item, index) => {
        if (index === 0) {
          footerData[item.field] = "总计";
        }
        if (["samplecnt", "cnt4", "cnt1", 'pcnt', 'prate'].includes(item.field)) {
          footerData[item.field] = XEUtils.sum(datas, item.field);
          if (item.field == 'prate') {
            if (datas.length > 0) {
              footerData[item.field] = Number(XEUtils.sum(datas, "pcnt") * 100 / XEUtils.sum(datas, "samplecnt")).toFixed(2) + "%";
            } else {
              footerData[item.field] = "0";
            }
          }
        }
      });
      datas.splice(datas.length, 0, footerData);
      let headers = [columns.map((item) => item.title)];
      return headers.concat(
        datas.map((row) => {
          return columns.map((column) => {
            return this.retForamtVal(row[column.field], column.field);
          });
        })
      );
    },
    BtnPrint() { },
    async InitPage() {
      if (this.infoitem == "") {
        this.$alert("点击查询条件中统计项目(红字标识)，先选择统计项目后再查询！", "信息");
        return false;
      }
      this.tableColumn = [];
      let field = this.infocode.split(",");
      let title = this.infoitem.split(",");
      field.forEach((item) => {
        if (!!item) {
          let data = this.defaultColumn.find((m) => m.field == item);
          if (!!data) {
            this.tableColumn.push(data);
          }
        }
      });
      console.log(this.tableColumn);
      console.log("this.infocode", this.infocode);
      this.loading = true;
      this.$tool
        .request({
          url: "LIS/LIS9/LIS911",
          method: "post",
          timeout: 600000,
          data: {
            action: "InitPage",
            infocode: this.infocode, //要查询的列数
            sortArr: this.sortArr, //排序
            datecode: this.datecode,
            ...this.searchobj,
          },
        })
        .then((response) => {
          console.log(response.resistrulescol);
          // ++this.xTablekey;
          // this.tableColumn = response.RData.Cols;
          this.tableData = response.Data;
          this.resistrulescolList = response.resistrulescol;
          this.loading = false;
        })
        .catch((e) => {
          this.$message.warning(e);
          this.loading = false;
        });
    },

    retForamtVal(cellValue, column) {
      if (["rp_hospitalcode"].includes(column)) {
        try {
          let hospname = this.hospOption.find((m) => m.data == cellValue);
          if (hospname != undefined && hospname != null) {
            return hospname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["rp_req_deptno"].includes(column)) {
        try {
          let deptname = this.deptOption.find((m) => m.data == cellValue);
          if (deptname != undefined && deptname != null) {
            return deptname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["rp_req_wardno"].includes(column)) {
        try {
          let deptname = this.wardOption.find((m) => m.data == cellValue);
          if (deptname != undefined && deptname != null) {
            return deptname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column == "rp_pat_typecode") {
        try {
          let pattypename = this.pattypeOption.find((m) => m.data == cellValue);
          if (pattypename != undefined && pattypename != null) {
            return pattypename.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["rp_result4"].includes(column)) {
        //申请医生
        try {
          let rescodename = this.rescodeOption.find((m) => m.data == cellValue);
          if (rescodename != undefined && rescodename != null) {
            return rescodename.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column == "rp_rptunitname") {
        try {
          let rptunitname = this.rptunitOption.find((m) => m.data == cellValue);
          if (rptunitname != undefined && rptunitname != null) {
            return rptunitname.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column == "rp_specimen_code") {
        try {
          let specimenname = this.specimenOption.find((m) => m.data == cellValue);
          if (specimenname != undefined && specimenname != null) {
            return specimenname.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column == "rp_pat_sex") {
        if (cellValue == "1") {
          return "男";
        } else if (cellValue == "2") {
          return "女";
        } else {
          return "";
        }
      } else {
        return cellValue;
      }
    },
    formatFun({ cellValue, column, row }) {
      return this.retForamtVal(cellValue, column.property);
    },
    cellClassName({ row, column }) {
      if (column.property == "samplecnt" || column.property == "cnt4" || column.property == "cnt1" || column.property == "pcnt") {
        if (parseInt(row[column.property]) > 0) {
          return "sample-tips";
        }
      }
    },
    footerCellClassName({ $rowIndex, column, columnIndex }) {
      if (columnIndex === 0 || ["samplecnt", "cnt4", "cnt1", "pcnt"].includes(column.property)) {
        if ($rowIndex === 0) {
          return "col-blue";
        } else {
          return "col-red";
        }
      }
    },
    footerMethod({ columns, data }) {
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 0) {
            return "总计";
          }
          if (["samplecnt", "cnt4", "cnt1", "pcnt"].includes(column.property)) {
            return XEUtils.sum(data, column.property);
          }
          if (column.property == "prate") {
            if (data.length > 0) {
              return Number(XEUtils.sum(data, "pcnt") * 100 / XEUtils.sum(data, "samplecnt")).toFixed(2) + "%";
            } else {
              return "0%";
            }
          }
          return null;
        }),
      ];
    },
    xTable1dblclick({ row, column }) {
      this[row.countcode] = false;
      try {
        var delrow = this.$refs.xTable1.getCurrentRow();
        if (delrow) {
          var alld = this.$refs.xTable1.tableData;
          var rowindex = alld.indexOf(delrow);
          this.$refs.xTable1.remove(delrow);
          let havedata = this.$refs.xTable1.tableData;
          if (havedata.length > 0) {
            if (rowindex >= havedata.length) rowindex = havedata.length - 1;
            let selectrow = havedata[rowindex];
            this.$refs.xTable1.setCurrentRow(selectrow);
          }
        }
      } catch (e) {
        console.log("error", e);
      }
    },
    bypatChange(e) {
      if (e == 1) {
        this.fieldtitle = "病人数";
      } else if (e == 2) {
        this.fieldtitle = "报告数";
      } else {
        this.fieldtitle = "标本数";
      }
      this.InitPage();
    },
    // resistrulesChange(e, row) {
    //     let resdict = this.rescodeOption.find(item => item.data == e);
    //     row.resistrulesname = resdict.display;
    // },
    // closedialog(value, name) {
    //     if (value != "close") {
    //         let resdict = this.resdictList.find(item => item.data == value);
    //         this.addMed.resistrules = value;
    //         if (resdict) {
    //             this.addMed.resistrulesname = resdict.display;
    //         } else {
    //             this.addMed.resistrulesname = value;
    //         }
    //     }
    //     this.dialogMultipleVisible = false;
    // },
  },
};
</Script>

<style scoped>
.pagetop {
  width: 100%;
  height: 160px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

::v-deep .pagetop .el-radio {
  margin-right: 10px !important;
}

.pagecenter {
  position: absolute;
  top: 165px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 0px;
  overflow: auto;
}

.el-checkbox__label {
  padding: 0px;
}

.left_nav {
  width: 20%;
  height: 100%;
  border-right: 1px solid #ccc;
  padding: 0px 0px 0px 0px;
  float: left;
  display: inline;
}

.left_nav div {
  cursor: pointer;
  height: 40px;
  width: 100%;
  float: left;
  padding-left: 20px;
  line-height: 40px;
}

.left_nav .active {
  background-color: DeepSkyBlue;
}

.right_nav {
  width: 80%;
  height: 100%;
  display: inline-block;
  vertical-align: top;
  float: left;
  display: inline;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

.table1style tr td {
  padding: 0px 2px 0px 5px;
}

::v-deep .sample-tips {
  color: blue;
  cursor: pointer;
  text-decoration: underline;
}

::v-deep .mytable-style .vxe-footer--column.col-blue {
  color: blue !important;
  font-weight: bold;
}

::v-deep .mytable-style .vxe-body--row.row-blue {
  color: blue !important;
  font-weight: bold;
}

::v-deep .el-checkbox__label {
  padding-left: 0px;
}

::v-deep .el-icon-time {
  line-height: 18px !important;
}

::v-deep .el-range__close-icon {
  line-height: 18px !important;
}

::v-deep .el-range-editor--small .el-range-separator {
  line-height: 17px !important;
}
</style>
